package cn.cleanarch.infra.idp.pms.controller;

import cn.cleanarch.infra.idp.commons.domain.dto.PageResult;
import cn.cleanarch.infra.idp.pms.domain.dto.ProjectCategoryDTO;
import cn.cleanarch.infra.idp.pms.domain.query.ProjectCategoryQuery;
import cn.cleanarch.infra.idp.pms.service.ProjectCategoryService;
import cn.cleanarch.infra.idp.web.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目分类管理控制器
 */
@RestController
@RequestMapping("/pms/project-category")
public class ProjectCategoryController {

    @Autowired
    private ProjectCategoryService projectCategoryService;

    /**
     * 分页查询项目分类
     */
    @GetMapping
    public Result pageQuery(ProjectCategoryQuery query) {
        PageResult<ProjectCategoryDTO> result = projectCategoryService.pageQuery(query);
        return Result.data(result);
    }

    /**
     * 获取所有项目分类
     */
    @GetMapping("/list-all")
    public Result listAll() {
        List<ProjectCategoryDTO> categories = projectCategoryService.listAll();
        return Result.data(categories);
    }

    /**
     * 根据ID获取项目分类
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Long id) {
        cn.cleanarch.infra.idp.pms.domain.entity.ProjectCategory category = projectCategoryService.getById(id);
        return Result.data(category);
    }

    /**
     * 创建项目分类
     */
    @PostMapping
    public Result create(@RequestBody ProjectCategoryDTO dto) {
        ProjectCategoryDTO result = projectCategoryService.create(dto);
        return Result.data(result);
    }

    /**
     * 更新项目分类
     */
    @PutMapping
    public Result update(@RequestBody ProjectCategoryDTO dto) {
        ProjectCategoryDTO result = projectCategoryService.update(dto);
        return Result.data(result);
    }

    /**
     * 删除项目分类
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Long id) {
        Boolean success = projectCategoryService.delete(id);
        return Result.data(success);
    }
}